package com.jt.assistant.utils

import java.net.NetworkInterface
import java.net.SocketException
import java.util.*


object NumberUtil {

    /**
     * 获取当前时间所在周的周一和周日的日期时间
     * @return
     */
    fun formatNum(num: Double): String {
        return String.format("%.0f", num)
    }

     fun getMachineHardwareAddress(): String? {
        var interfaces: Enumeration<NetworkInterface?>? = null
        try {
            interfaces = NetworkInterface.getNetworkInterfaces()
        } catch (e: SocketException) {
            e.printStackTrace()
        }
        var hardWareAddress: String? = ""
        var iF: NetworkInterface? = null
        if (interfaces == null) {
            return null
        }
        while (interfaces.hasMoreElements()) {
            iF = interfaces.nextElement()
            try {
                hardWareAddress = bytesToString(iF!!.hardwareAddress)
                if (hardWareAddress != null) break
            } catch (e: SocketException) {
                e.printStackTrace()
            }
        }
        return hardWareAddress!!
    }

    private fun bytesToString(bytes: ByteArray?): String? {
        if (bytes == null || bytes.size == 0) {
            return null
        }
        val buf = StringBuilder()
        for (b in bytes) {
            buf.append(String.format("%02X:", b))
        }
        if (buf.length > 0) {
            buf.deleteCharAt(buf.length - 1)
        }
        return buf.toString()
    }
}